package dyyx.word;

import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

import dyyx.LuceneUtil;
import dyyx.domain.WordFrequency;
import dyyx.file.FileScanUtil;
import dyyx.file.ScanContext;

public class WordFreq {
	
	public static void main(String[] args) throws Exception {
		
		
		
		ScanContext context = new ScanContext();
		WordFreqHandler handler = new WordFreqHandler();
		context.handler = handler;
		String dir = "/Users/dugang/fun/hellocode/web/docs/";
		File file = new File(dir);
		
		FileScanUtil.doScan(file, context);

		Map<String,AtomicLong> dataMap  = handler.getDataMap();
		int num = dataMap.size();
		
		System.out.println(" data map size "+num);
		
	    List<WordFrequency> list = LuceneUtil.buildWordFrequencys(dataMap);

		int top = 300;

		num = list.size();
		if(top > num){
			top = num;
		}
		WordFrequency wf = null;
		for(int i=0;i<top;i++){
			wf = list.get(i);
			System.out.println(wf.word+"="+wf.frequency);
		}
		
		
		
		
		
		
	
	}
}
